home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / pack / xfh132.lzh / XFH / src / pack.c < prev    next >
C/C++ Source or Header  |  1993-01-19  |  3KB  |  104 lines

  1. /* pack.c - packer-support routines.
  2.    Copyright (C) 1991, 1992, 1993 Kristian Nielsen.
  3.  
  4.    This file is part of XFH, the compressing file system handler.
  5.  
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            */
  19.  
  20. /* $Log:    pack.c,v $
  21.  * Revision 1.2  93/01/14  15:29:37  Kristian
  22.  * Added RCS keywords.
  23.  * 
  24.  */
  25.  
  26. #include "CFS.h"
  27. #include <dossupport.h>
  28.  
  29. #define MAKELONGID(a,b,c,d) \
  30. ( (ULONG)(a)<<24 | (ULONG)(b)<<16 | (ULONG)(c)<<8 | (ULONG)(d) )
  31. #define LID_PACK MAKELONGID('P','A','C','K')
  32. #ifdef NUKE_SUPPORT
  33. #define LID_NUKE MAKELONGID('N','U','K','E')
  34. #endif
  35. #ifdef POWERPACKER_SUPPORT
  36. #define LID_PP20 MAKELONGID('P','P','2','0')
  37. #endif
  38.  
  39.  
  40. #define GETID(id) xRead(glob, xfh, &(id), 4)
  41.  
  42. /* The purpose of this function is to determine what kind of file a
  43.  * (x)filehandle belongs to. Currently, this is done with a massive 'if',
  44.  * that is, it needs to be hardwired into the cfs. It would be nice to
  45.  * have a more open system - something like a list that a set of shared
  46.  * libraries could hook into, each catering for some subset of the
  47.  * supported file types.
  48.  *
  49.  * An idea would be to have an ARexx interface. Not exactly fast, but
  50.  * this way even the casual user could have the filesystem handle
  51.  * almost any file conversion through the CFS themselves! (Say, like
  52.  * converting graphics data in file format XYZZ12 from messydos machines
  53.  * to IFF).
  54.  *
  55.  */
  56. LONG xFileType( glb glob, struct FileHandle *xfh ){
  57.    ULONG idbuf;
  58.    LONG objtype=XOBJECT;
  59.  
  60.    /* Check for a format recognisable by longword id. */
  61.    /* (At this point in time, only XPK and XOBJ are supported). */
  62. #ifdef OBSOLETE_PRE_XPK_PACKER_SUPPORT
  63.    if( GETID(idbuf) == 4) switch(idbuf){
  64.       case LID_PACK:
  65.          if( GETID(idbuf) == 4) switch( idbuf ){
  66. #ifdef NUKE_SUPPORT
  67.             case LID_NUKE:
  68.                objtype = NUKEOBJECT;
  69.                goto return_type;
  70. #endif
  71.             default:
  72.                objtype = XPKOBJECT;
  73.                goto return_type;
  74.          }
  75.          break;
  76. #ifdef POWERPACKER_SUPPORT
  77.       case LID_PP20:
  78.          objtype = PPACKOBJ;
  79.          goto return_type;
  80. #endif
  81.       default:
  82.          break;          /* Unknown main id. */
  83.    }
  84. #endif
  85.  
  86.    /* If checking for another type, remember to xSeek() if nessesary. */
  87.    debug(("Checking if file is Xpk..."));
  88.    xSeek( glob, xfh, 0L, OFFSET_BEGINNING );
  89.    if( IsXpkFile( glob, xfh )){
  90.       debug(("YES!\n"));
  91.       objtype = XPKOBJECT;
  92.       goto return_type;
  93.    }
  94.    debug(("No.\n"));
  95.    
  96.  return_type:
  97.    xSeek( glob, xfh, 0L, OFFSET_BEGINNING );
  98.    return objtype;
  99. }
  100.  
  101. #undef GETID
  102.  
  103. /* End of pack.c */
  104.